package com.gdit.zax.utils;

import java.text.SimpleDateFormat;
import java.util.Date;


public class DateUtil {
	
	/**
	 * 获取日期中的月份(*年*月*日) 
	 * 
	 * @return
	 */
	public static Date getDate(String datestring,String format) {
		if (format==null) {
			format ="yyyy-MM-dd HH:mm:ss";
		}
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format);
			Date date = sdf.parse(datestring);
			return date;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Date toDate (String dateString) {
		try  
		{  
		    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");  
		    Date date = sdf.parse(dateString);  
		    return date;
		}  
		catch (Exception e)  
		{  
		    System.out.println(e.getMessage());  
		}  
		return null;
	}
}
